#include "multi_button_combobox.h"
#include "multi_list_widget.h"
#include <QWidgetAction>
#include <QMenu>

MultiButtonComboBox::MultiButtonComboBox(QWidget* parent) : QPushButton(parent)
{
    auto menu = new QMenu(this);

    m_ptr = new MultiListWidget(this);
    QWidgetAction *action = new QWidgetAction(this);
    action->setDefaultWidget(m_ptr);
    menu->addAction(action);
    setMenu(menu);

    connect(m_ptr, &MultiListWidget::signal_text, this, [this](const QString& text)
    {
       setText(text);
    });
}

void MultiButtonComboBox::addItem(const QString& text, const QVariant& data)
{
    m_ptr->addItem(text, data);
}

void MultiButtonComboBox::setData(const QVariant& data)
{
    m_ptr->setData(data);
}

QVariant MultiButtonComboBox::data() const
{
    return m_ptr->data();
}
